<template>
	<view class="page">
		<template v-if="isNetwork">
			<template>
				<view :class="tabtarIndex==0?'page':''" v-if="tabtarIndex==0">
					<home></home>
				</view>
				<view :class="tabtarIndex==1?'page':''" v-if="tabtarIndex==1">
					<GoodsClass></GoodsClass>
				</view>
				<view :class="tabtarIndex==2?'page':''" v-if="tabtarIndex==2">
					<shopping-cart></shopping-cart>
				</view>
				<view :class="tabtarIndex==3?'page':''" v-if="tabtarIndex==3">
					<user></user>
				</view>
			</template>
			<helang-tab-bar-roll v-if="tabtarIndex || tabtarIndex == '0'" :tabtarIndex.sync="tabtarIndex" :tabList="tabList"
				@changeTabtarIndex="changeTabtarIndex"></helang-tab-bar-roll>
		</template>
		<template v-if="!isNetwork">
			<view style="position: fixed; width: 100%; text-align: center; top: 40%; color: #666666; font-size: 12px;">
				<view>哎呀，网络信号丢失了</view>
				<view>请检查网络，或前往<text style="color: #3c9cff; text-decoration: underline;" @click="openAppAuthorizeSetting">设置</text></view>
				<u-button size="mini" type="primary" text="点击重试" style="width: 120rpx; margin-top: 10rpx;" @click="openRetry "></u-button>
			</view>
		</template>

		
		<!-- <u-no-network
			@disconnected="disconnected"
			@connected="connected"
			@retry="retry"
		></u-no-network> -->
	</view>
</template>

<script>
	import cookie from "@/utils/store/cookie";
	import Home from "@/pages/home/index";
	import GoodsClass from "@/pages/shop/GoodsClass/index";
	import ShoppingCart from "@/pages/shop/ShoppingCart/index";
	import User from "@/pages/user/User/index";

	import tabBarRoll from "@/uni_modules/helang-tabBar/components/helang-tabBar/tab-bar-roll";


	export default {
		name: "Launch",
		data() {
			return {
				history: [],
				tabtarIndex: null,
				isNetwork: true,
				tabList: [
				{
					"image":"https://qny.yijiumy.com/1855/sy.png ",
					"text":"首页",
					"image_h": "https://qny.yijiumy.com/1855/shouye.png"
				},
				{
					"image":" https://qny.yijiumy.com/1855/-h-fenlei.png",
					"text":"分类",
					"image_h": "https://qny.yijiumy.com/1855/fl.png"
				},
					{
						"image":"https://qny.yijiumy.com/1855/gwc.png",
						"text":"购物车",
						"image_h": "https://qny.yijiumy.com/1855/gwc2.png"
					},
					{
						"image":"https://qny.yijiumy.com/1855/wd.png",
						"text":"我的",
						"image_h": "https://qny.yijiumy.com/1855/wd2.png"
					},
				]
			};
		},
		components: {
			Home,
			GoodsClass,
			ShoppingCart,
			User,
			"helang-tab-bar-roll": tabBarRoll
		},
		methods: {
			openRetry() {
				this.$yrouter.reLaunch({
					path: "/pages/launch/index"
				});
			},
			openAppAuthorizeSetting() {
				uni.openAppAuthorizeSetting({
				  success (res) {
				    console.log(res)
				  }
				})
			},
			changeTabtarIndex(e) {
				this.tabtarIndex = e
			}
			, disconnected() {
				console.log('disconnected');
			},
			connected() {
				console.log('connected');
			},
			retry() {
				console.log('retry');
				this.$yrouter.reLaunch({
					path: "/pages/launch/index"
				});
			}
		},
		onLoad() {
			switch (this.$yroute.query.type) {
				case 'Home':
					this.tabtarIndex = 0
					break;
				case 'GoodsList':
					this.tabtarIndex = 1
					break;
				case 'ShoppingCart':
					this.tabtarIndex = 2
					break;
				case 'User':
					this.tabtarIndex = 3
					break;

				default:
					this.tabtarIndex = 0
					break;
			}
		},
		onShow() {
			const self = this
			uni.getNetworkType({
				success: function (res) {
					console.log(res.networkType);
					if(res.networkType == 'none') {
						self.isNetwork = false
					}
				}
			});
		}
	};
</script>